package com.baturu.vin.honda.script;

import com.baturu.carvin.dal.dao.ExtendPartsTypeDAO;
import com.baturu.vin.client.entity.ExtendPartsTypeEntity;
import com.baturu.vin.honda.dal.dao.SimpleDAO;
import com.baturu.vin.honda.dto.HondaPartsInfoDTO;
import com.baturu.vin.honda.dto.HondaPartsMappingDTO;
import com.baturu.vin.test.AbstractBaseCase;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: chenjiahao
 * @Time: 2019/10/15
 */
public class ExtendPartsType extends AbstractBaseCase {

    @Autowired
    ExtendPartsTypeDAO extendPartsTypeDAO;

    @Autowired
    SimpleDAO simpleDAO;

    @Test
    public void name() {
        List<String> nList = Lists.newArrayList();
        List<ExtendPartsTypeEntity> extendPartsName = extendPartsTypeDAO.queryEPCPartsName("dc_parts_20191012", "本田");
        extendPartsName.forEach(d->{
            try {
                HondaPartsMappingDTO epcPartsName = simpleDAO.queryPartsName(d.getPartsName());
                HondaPartsInfoDTO partsInfoDTO = simpleDAO.queryImageCode(epcPartsName.getPartsCode());
                List<HondaPartsMappingDTO> partsMappingDTOS = simpleDAO.queryBtrPartsName(partsInfoDTO);

                for (HondaPartsMappingDTO btrPartsName : partsMappingDTOS) {
                    ExtendPartsTypeEntity extendPartsTypeEntity = extendPartsTypeDAO.queryTreeByBtrPartsName(btrPartsName.getBtrPartsName());
                    if (StringUtils.isNotBlank(extendPartsTypeEntity.getTree0())) {
                        extendPartsTypeDAO.updateEpcPartsName(extendPartsTypeEntity, d.getPartsName());
                        break;
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
                nList.add(d.getPartsName());
            }
        });
        System.out.println(nList);
    }
}
